package com.app.micaihu.utils

import androidx.collection.ArrayMap
import com.app.micaihu.configure.AppConfigTools
import com.app.micaihu.view.utils.ParamsMap
import com.app.utils.util.StringUtils
import java.util.*

/**
 * 公共参数
 */
object ParamsMapUtils {

    @JvmStatic
    val commonParams: ArrayMap<String, Any>
        get() {
            val params = ArrayMap<String, Any>()
//            params["versioncode"] = AppUtils.getAppVersionCode()
//            params["app_version"] = AppUtils.getAppVersionName()
//            params["app_channel"] = ChannelUtil.getChannel(Utils.getApp())
//            params["os_sdk"] = Build.VERSION.SDK_INT
//            params["os_version"] = Build.MODEL + "," + Build.VERSION.RELEASE
////            params["device_uuid"] = UidUtils.getDeviceId()
//            params["platform"] = 0
            return params
        }

    /**
     * map包装类的md5加密
     *
     * @param parmsMap
     */
    @JvmStatic
    fun paramsMapMD5(paramsMap: ParamsMap?) {
        if (paramsMap == null) {
            return
        }
        //生成时间戳
        val timestamp = "" + System.currentTimeMillis()
        //加入时间戳参数
        paramsMap.putValue("timestamp", timestamp)
        val key: Array<Any> = paramsMap.keys.toTypedArray()
        if (key == null || key.size == 0) {
            return
        }
        Arrays.sort(key) //升序排列
        //待加密字符串
        val verifyMsg = StringBuffer()
        //倒序输出
        for (i in key.indices.reversed()) {
            verifyMsg.append(key[i].toString() + "=" + paramsMap[key[i]] + "&")
        }
        //拼接版本标识
        verifyMsg.append(AppConfigTools.APICODE)
        //进行MD5加密
        val verifyMsgMd5 = StringUtils.md5(verifyMsg.toString())
        //加入加密字符串参数
        paramsMap.putValue("verifyMsg", verifyMsgMd5)
    }
}